package com.videoanswer.van.web.client.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.videoanswer.van.web.client.model.AnswerTeacher;
import com.videoanswer.van.web.client.model.TeacherSearchInfo;
import com.videoanswer.van.web.client.utils.Pager;

@Controller
public class RealTimeAnswerController {
	@RequestMapping(value = { "/realTimeAnswer" }, method = { RequestMethod.GET })
	public ModelAndView realTimeAnswer(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		
		return new ModelAndView("/realTimeAnswer", map);
	}
	
	@RequestMapping(value = { "/moreOnlineTeachers"}, method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView moreForecastCourses(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		TeacherSearchInfo teacherSearchInfo = new TeacherSearchInfo();
		int studyingPhase = 2;
		int subject = 0;
		int showWay = 0;
		
		if(null != request.getParameter("studyingPhase")){
			studyingPhase = Integer.parseInt(request.getParameter("studyingPhase"));
		}
		teacherSearchInfo.setStudyingPhase(studyingPhase);
		
		if(null != request.getParameter("subject")){
			subject = Integer.parseInt(request.getParameter("subject"));
		}
		teacherSearchInfo.setSubject(subject);
		
		if(null != request.getParameter("showWay")){
			showWay = Integer.parseInt(request.getParameter("showWay"));
		}
		teacherSearchInfo.setShowWay(showWay);
		
		map.put("teacherSearchInfo", teacherSearchInfo);
		
		Pager pager = new Pager();
		
		int currentPage = 0;
		int perPageCount = 5;
		
		if(null != request.getParameter("currentPage")){
			currentPage = Integer.parseInt(request.getParameter("currentPage"));
		}
		
		if(null != request.getParameter("perPageCount")){
			perPageCount = Integer.parseInt(request.getParameter("perPageCount"));
		}
		
		pager.setCurrentPage(currentPage);
		pager.setPerPageCount(perPageCount);
		pager.setTotalCount(52);
		pager.setTotalPage(6);
		
		List <AnswerTeacher> answerTeacherList = new ArrayList<AnswerTeacher>();
		AnswerTeacher answerTeacher = new AnswerTeacher();
		
		answerTeacher.setAnswerTimes(245);
		answerTeacher.setOnline(true);
		answerTeacher.setScore(3.5f);
		answerTeacher.setTeacherImgUrl("http://imgstatic.baidu.com/img/image/shouye/duanfa0816.jpg");
		answerTeacher.setTeacherMainPageUrl("");
		answerTeacher.setTeacherName("乔布斯");
		answerTeacher.setTeacherStudyPhase("高中");
		answerTeacher.setTeachingSubject("数学");
		
		for(int i=0; i<perPageCount; i++){
			answerTeacherList.add(answerTeacher);
		}
		
		pager.setDatas(answerTeacherList);
		
		map.put("pageView", pager);
		
		return new ModelAndView("/subRealTimeAnswer/moreOnlineTeachers", map);
	}
	
	
	@RequestMapping(value = { "/moreRelativeNews" }, method = { RequestMethod.GET })
	public ModelAndView moreRelativeNews(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		
		return new ModelAndView("/subRealTimeAnswer/moreRelativeNews", map);
	}

}
